package cn.qayy.service.impl;

import cn.qayy.dao.SignInMapper;
import cn.qayy.dto.signInDTO;
import cn.qayy.po.SignIn;
import cn.qayy.service.ISignInService;
import cn.qayy.utils.DateUtils;
import com.github.pagehelper.PageHelper;
import org.apache.poi.ss.usermodel.DateUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.RequestParam;

@Service("signInServiceImpl")
public class SignInServiceImpl implements ISignInService {
	private Logger logger = LoggerFactory.getLogger(SignInServiceImpl.class);

	@Resource
	private SignInMapper signInMapper;

	@Override
	public PageInfo<Map<String, Object>> selectSignBy(@RequestParam Map<String, Object> params) throws Exception{
		if (params != null && params.size() > 0) {
			if (params.containsKey("pageNumber") && params.containsKey("pageSize")) {
				Integer pageNum = Integer.parseInt((String) params.get("pageNumber"));
				Integer pageSize = Integer.parseInt((String) params.get("pageSize"));
				PageHelper.startPage(pageNum, pageSize);
			}
			List<Map<String, Object>> list = signInMapper.selectSignInBy(params);
			for (Map<String, Object> maplist : list) {
				String strDate = maplist.get("riqi").toString();
				Date ddate = DateUtils.strToDate(strDate, "yyyy/MM/dd");
				maplist.put("week", DateUtils.getWeekOfDate(ddate));
			}
			PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(list);
			return pageInfo;
		}
		return null;
	}

	@Override
	public List<signInDTO> selectSignInForDown(@RequestParam Map<String, Object> params) {
		List<signInDTO> list = signInMapper.selectSignInForDown(params);
		return list;
	}
}
